package nk.stack;

import java.util.Scanner;

public class AB1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        MyStack stack = new MyStack(n);
        String[] commad = new String[2];
        while (in.hasNextLine()) {
            commad = in.nextLine().split(" ");
            if ("push".equals(commad[0])) {
                stack.push(Integer.valueOf(commad[1]));
            } else if ("pop".equals(commad[0]))
                stack.pop();
            else stack.top();
        }
    }
}

class MyStack {
    int[] nums;
    int top = -1;

    public MyStack(int size) {
        this.nums = new int[size];
    }

    public void push(int x) {
        nums[++top] = x;
    }

    public void pop() {
        if (top < 0)
            System.out.println("error");
        else {
            System.out.println(nums[top]);
            top--;
        }
    }
    public void top() {
        if (top < 0)
            System.out.println("error");
        else System.out.println(nums[top]);
    }
}